package com.biz.service.mall;


import com.alibaba.fastjson.JSON;
import com.biz.conf.Global;
import com.biz.model.Hmodel.basic.*;
import com.biz.model.Hmodel.goods.baseStandard;
import com.biz.model.Hmodel.goods.goodsBrand;
import com.biz.model.Hmodel.goods.goodsUnit;
import com.biz.model.Pmodel.Ppics;
import com.biz.model.Pmodel.PwxGood;
import com.biz.model.Pmodel.PwxGoods;
import com.biz.model.Pmodel.PwxGoodsStock;
import com.biz.model.Pmodel.basic.*;
import com.biz.model.Pmodel.sys.PwxGoodsForStock;
import com.biz.service.base.BaseServiceImpl;
import com.framework.dao.hdao.BaseDaoI;
import com.framework.dao.mdao.DaoSupport;
import com.framework.model.Pager;
import com.framework.utils.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.*;

//import com.biz.model.Pmodel.basic.PwxgoodsStock;

/**
 * Created by liujiajia on 2017/1/6.
 */
@Service("mallService")
public class MallServiceImpl extends BaseServiceImpl<Twxgoods> implements MallServiceI {

    @Resource(name = "daoSupport")
    private DaoSupport dao;

    @Autowired
    private BaseDaoI<TwxGoodsGroup> wxgoodsGroupDao;

    @Autowired
    private BaseDaoI<Twxgoods> twxgoodsDao;

    @Autowired
    private BaseDaoI<Twxgoods2> twxgoodsDao2;

    @Autowired
    private BaseDaoI<TgoodsTag> tgoodsTagDao;

    @Autowired
    private BaseDaoI<Ttag> tagDao;

    @Autowired
    private BaseDaoI<goodsUnit> unitsDao;

    @Autowired
    private BaseDaoI<goodsBrand> brandDao;

    @Autowired
    private BaseDaoI<Tpics> picsDao;

    @Autowired
    private BaseDaoI<baseStandard> standDao;


    @Autowired
    private BaseDaoI<TwxgoodsProperty> wxgoodsPropertyDao;

    @Autowired
    private BaseDaoI<TwxgoodsStock> wxgoodsStockDao;

    @Autowired
    private BaseDaoI<TwxgoodsStock2> wxgoodsStockDao2;


    @Override
    public Pager<Pwxgoods> queryMall(Pager<Pwxgoods> pager) throws Exception {
        Pager<Pwxgoods> pagerRe = dao.findForPager1("mallDao.showUnionMall","mallDao.showUnionMallCount", pager);
        return pagerRe;
    }

    @Override
    public List<TwxGoodsGroup> loadGoodsGroup(String mapId) throws Exception {
        String hql = StringUtil.formateString("from TwxGoodsGroup where isdel=0 and shopid='{0}'", mapId);
        return wxgoodsGroupDao.find(hql);
    }

    @Override
    public void upOrdown(String ids, String state, String userId, String type) throws Exception {
        if (!StringUtil.isNullOrEmpty(ids)) {
            String hql = StringUtil.formateString("update Twxgoods t set t.isSale='{1}' where t.id in({0})", StringUtil.formatSqlIn(ids), state);
            twxgoodsDao.executeHql(hql);
        }

    }


    @Override
    public List<TgoodsTag> loadGoodsTagsByGoodsId(String goodsId) throws Exception {
        String hql = StringUtil.formateString("from TgoodsTag where isdel=0 and goodsId='{0}'", goodsId);
        return tgoodsTagDao.find(hql);
    }

    @Override
    public void saveGoodsInfo(PwxGoods label_list, String shopId) throws Exception {
        Ttag tag=tagDao.getById(Ttag.class,label_list.getTag());
        TwxGoodsGroup group=wxgoodsGroupDao.getById(TwxGoodsGroup.class,label_list.getGroupId());
        //List<Tpics> pics=picsDao.findBySql("from Tpics where ")
        goodsUnit unit=unitsDao.getById(goodsUnit.class,label_list.getUnitId());
        goodsBrand brand=brandDao.getById(goodsBrand.class,label_list.getBrand());

        if(brand==null)
        {
            brand=new goodsBrand();
            brand.setId(label_list.getBrand());
            brand.setName(label_list.getBrandName());
            brand.setType(1);
            brandDao.save(brand);
        }
        if(unit==null)
        {
            unit=new goodsUnit();
            unit.setId(label_list.getUnitId());
            unit.setName(label_list.getUnitName());
            unit.setType(1);
            unitsDao.save(unit);;
        }
        Ptag  tt=new Ptag();
        Pgroup  tg=new Pgroup();
        if(tag==null)
        {

            tt.setName(label_list.getTagName());
            tt.setId(label_list.getTag());
            tt.setShopid(shopId);
            dao.save("mallDao.saveTag",tt);
        }
        if(group==null)
        {
            String picId="";
            if(!StringUtil.isNullOrEmpty(label_list.getGroupPath())) {
                Tpics pics = new Tpics();
                pics.setPath(label_list.getGroupPath().replace("http://9900oss.oss-cn-hangzhou.aliyuncs.com/", ""));
                picsDao.save(pics);
                picId=pics.getId();
            }

            tg.setName(label_list.getGroupName());
            tg.setId(label_list.getGroupId());
            tg.setIcon(picId);
            tg.setShopid(shopId);
            dao.save("mallDao.saveGroup",tg);
        }
        Map<String,String> map=new HashMap<>();
        map.put("group",label_list.getGroupId());
        map.put("tag",label_list.getTag());
        List<String> list= (List<String>) dao.findForList("mallDao.getTagGroup",map);
        if(list==null||list.size()<=0)
        {
            map.put("id", UuidUtil.get32UUID());
            dao.save("mallDao.saveTagGroup",map);
        }
        if(label_list.getCoverList()!=null&&label_list.getCoverList().size()>0)
        {
            for(int i=0;i<label_list.getCoverList().size();i++)
            {
                Tpics tp=picsDao.getById(Tpics.class,label_list.getCoverList().get(i).getCoverId());
                if(tp==null)
                {
                    Ppics pics=new Ppics();
                    pics.setPath(label_list.getCoverList().get(i).getCoverPath().replace("http://9900oss.oss-cn-hangzhou.aliyuncs.com/",""));
                    pics.setMainType(1);
                    pics.setId(label_list.getCoverList().get(i).getCoverId());
                    //  picsDao.save(pics);
                    dao.save("mallDao.saveGoodsPics",pics);
                }

            }

        }
        saveStandardForInterface(label_list,shopId);

    }

    private void saveStandardForInterface(PwxGoods label_list, String shopId) throws Exception {
        if(label_list.getStocklist()!=null&&label_list.getStocklist().size()>0)
        {
            List<Pstandard> list=new ArrayList<>();
            for(int i=0;i<label_list.getStocklist().size();i++)
            {
                if(!StringUtil.isNullOrEmpty(label_list.getStocklist().get(i).getTypesId1())) {
                    baseStandard s1 = standDao.getById(baseStandard.class, label_list.getStocklist().get(i).getTypesId1());
                    baseStandard s1p = standDao.getById(baseStandard.class, label_list.getStocklist().get(i).getStandard1Pid());
                    if(s1==null)
                    {
                        Pstandard s=new Pstandard();
                        s.setId(label_list.getStocklist().get(i).getTypesId1());
                        s.setName(label_list.getStocklist().get(i).getStandard1Name());
                        s.setShopId(shopId);
                        s.setPid(label_list.getStocklist().get(i).getStandard1Pid());
                        if(list!=null&&list.size()>0) {
                            boolean isIn=false;
                            for (int j = 0; j < list.size(); j++) {
                                if (list.get(j).getId().equals(s.getId()))
                                {
                                    isIn=true;
                                }
                            }
                            if(!isIn)
                            {list.add(s);}
                        }else
                        {
                            list=new ArrayList<>();
                            list.add(s);
                        }
                    }
                    if(s1p==null)
                    {
                        Pstandard s=new Pstandard();
                        s.setId(label_list.getStocklist().get(i).getStandard1Pid());
                        s.setName(label_list.getStocklist().get(i).getStandard1Pname());
                        s.setShopId(shopId);
                        s.setPid("0");
                        if(list!=null&&list.size()>0) {
                            boolean isIn=false;
                            for (int j = 0; j < list.size(); j++) {
                                if (list.get(j).getId().equals(s.getId()))
                                {
                                    isIn=true;
                                }
                            }
                            if(!isIn)
                            {list.add(s);}
                        }else
                        {
                            list=new ArrayList<>();
                            list.add(s);
                        }


                    }
                }

                if(!StringUtil.isNullOrEmpty(label_list.getStocklist().get(i).getTypesId2())) {
                    baseStandard s2 = standDao.getById(baseStandard.class, label_list.getStocklist().get(i).getTypesId2());
                    baseStandard s2p = standDao.getById(baseStandard.class, label_list.getStocklist().get(i).getStandard2Pid());
                    if(s2==null)
                    {
                        Pstandard s=new Pstandard();
                        s.setId(label_list.getStocklist().get(i).getTypesId2());
                        s.setName(label_list.getStocklist().get(i).getStandard2Name());
                        s.setShopId(shopId);
                        s.setPid(label_list.getStocklist().get(i).getStandard2Pid());
                        if(list!=null&&list.size()>0) {
                            boolean isIn=false;
                            for (int j = 0; j < list.size(); j++) {
                                if (list.get(j).getId().equals(s.getId()))
                                {
                                    isIn=true;
                                }
                            }
                            if(!isIn)
                            {list.add(s);}
                        }else
                        {
                            list=new ArrayList<>();
                            list.add(s);
                        }
                    }
                    if(s2p==null)
                    {
                        Pstandard s=new Pstandard();
                        s.setId(label_list.getStocklist().get(i).getStandard2Pid());
                        s.setName(label_list.getStocklist().get(i).getStandard2Pname());
                        s.setShopId(shopId);
                        s.setPid("0");
                        if(list!=null&&list.size()>0) {
                            boolean isIn=false;
                            for (int j = 0; j < list.size(); j++) {
                                if (list.get(j).getId().equals(s.getId()))
                                {
                                    isIn=true;
                                }
                            }
                            if(!isIn)
                            {list.add(s);}
                        }
                        else
                        {
                            list=new ArrayList<>();
                            list.add(s);
                        }
                    }
                }
                if(!StringUtil.isNullOrEmpty(label_list.getStocklist().get(i).getTypesId3())) {
                    baseStandard s3 = standDao.getById(baseStandard.class, label_list.getStocklist().get(i).getTypesId3());
                    baseStandard s3p = standDao.getById(baseStandard.class, label_list.getStocklist().get(i).getStandard3Pid());

                    if(s3==null)
                    {
                        Pstandard s=new Pstandard();
                        s.setId(label_list.getStocklist().get(i).getTypesId3());
                        s.setName(label_list.getStocklist().get(i).getStandard3Name());
                        s.setShopId(shopId);
                        s.setPid(label_list.getStocklist().get(i).getStandard3Pid());
                        if(list!=null&&list.size()>0) {
                            boolean isIn=false;
                            for (int j = 0; j < list.size(); j++) {
                                if (list.get(j).getId().equals(s.getId()))
                                {
                                    isIn=true;
                                }
                            }
                            if(!isIn)
                            {list.add(s);}
                        }else
                        {
                            list=new ArrayList<>();
                            list.add(s);
                        }
                    }


                    if(s3p==null)
                    {
                        Pstandard s=new Pstandard();
                        s.setId(label_list.getStocklist().get(i).getStandard3Pid());
                        s.setName(label_list.getStocklist().get(i).getStandard3Pname());
                        s.setShopId(shopId);
                        s.setPid("0");
                        if(list!=null&&list.size()>0) {
                            boolean isIn=false;
                            for (int j = 0; j < list.size(); j++) {
                                if (list.get(j).getId().equals(s.getId()))
                                {
                                    isIn=true;
                                }
                            }
                            if(!isIn)
                            {list.add(s);}
                        }
                        else
                        {
                            list=new ArrayList<>();
                            list.add(s);
                        }

                    }
                }
            }
            if(list!=null&&list.size()>0){
                Map<String,Object> map=new HashMap<>();
                map.put("list",list);
                dao.save("mallDao.saveStandardForInterface",map);}
        }
    }

    @Override
    public PwxGood getGoodsSku(String id) throws Exception {
        PwxGood res=new PwxGood();
        List<PwxGoodsStock> stocklist= (List<PwxGoodsStock>) dao.findForList("mallDao.getStocklist", id);
        List<PwxGoodsStock> stockParList=(List<PwxGoodsStock>) dao.findForList("mallDao.getStockParList", id);
        res.setId(id);
        res.setStocklist(stocklist);
        res.setStockParList(stockParList);
        return res;
    }

    @Override
    public List<Map<String, Object>> loadGroup(String pid) throws Exception {
        return (List<Map<String, Object>>)dao.findForList("mallDao.loadGroup",pid);
    }

    @Override
    public String addGroup(Map map) throws Exception {
        dao.save("mallDao.addGroup",map);
        return "操作成功";
    }

    @Override
    public List<Brand> showVenderId(String name) throws Exception {
        Map<String,String> map1=new HashMap<>();
        if(name!=null&&!name.trim().equals("")){
            map1.put("searchtext",name);
        }else{
            map1.put("searchtext", "");
        }
        List<Brand> list=(List<Brand>) dao.findForList("brandMapper.findMerchantGrid",map1);
        return list;
    }

    @Override
    public Map<String, Object> saveGoodsAndStock(Pwxgoods pwxgoods) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String goodsId = "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(pwxgoods.getPage_type()!=null&&pwxgoods.getPage_type().equals("update")){
            Twxgoods twxgoods = twxgoodsDao.getById(Twxgoods.class, pwxgoods.getId());
            goodsId = twxgoods.getId();
            BeanUtils.copyProperties(pwxgoods, twxgoods, new String[]{"isSale","buyerId","createTime", "discount", "isdel", "sendTime", "saleTime"});
            twxgoods.setIsdel((short) 0);
            twxgoods.setStartTime(sdf.parse(pwxgoods.getStartTime()));
            twxgoods.setEndTime(sdf.parse(pwxgoods.getEndTime()));
            twxgoods.setCreateTime(new Date());
            twxgoods.setSales(0);
            twxgoods.setInfo(pwxgoods.getInfo());
            twxgoodsDao.update(twxgoods);
            //更新商品图片
            String hql = StringUtil.formateString("update Tpics set isdel=1 where mainId='{0}'", twxgoods.getId());
            picsDao.executeHql(hql);
            if (!pwxgoods.getGoodsPicId().isEmpty()) {
                hql = StringUtil.formateString("update Tpics set isdel=0,mainId='{0}' where id in({1})", twxgoods.getId(), StringUtil.formatSqlIn(pwxgoods.getGoodsPicId()));
                picsDao.executeHql(hql);
            }
            map.put("msg", "修改成功！");
        }else {
            //新增商品
            Twxgoods twxgoods = new Twxgoods();
            BeanUtils.copyProperties(pwxgoods, twxgoods, new String[]{"createTime", "isdel"});
            twxgoods.setIsdel((short) 0);
            twxgoods.setCreateTime(new Date());
            twxgoods.setIsSale(Short.parseShort("1"));
            twxgoods.setSales(0);
            twxgoods.setStartTime(sdf.parse(pwxgoods.getStartTime()));
            twxgoods.setEndTime(sdf.parse(pwxgoods.getEndTime()));
            twxgoods.setInfo(pwxgoods.getInfo());
            goodsId = (String) twxgoodsDao.save(twxgoods);
            if (pwxgoods.getGoodsPicId() != null && !pwxgoods.getGoodsPicId().isEmpty()) {
                String hql = StringUtil.formateString("update Tpics t set t.mainId='{0}' where id in({1})", twxgoods.getId(), StringUtil.formatSqlIn(pwxgoods.getGoodsPicId()));
                picsDao.executeHql(hql);
            }
            map.put("msg", "修改成功！");
        }
        return  map;
    }

    @Override
    public Pwxgoods getByIdBySql(String id) throws Exception {
        return (Pwxgoods) dao.findForObject("mallDao.getByIdBySql", id);
    }

    @Override
    public List<PwxgoodsProperty> getwxgoodsProperty(String id) throws Exception {
        return (List<PwxgoodsProperty>) dao.findForList("mallDao.findWxgoodsPropertyList", id);
    }

    @Override
    public List<PwxgoodsStock> getwxgoodsStock(String id) throws Exception {
        return (List<PwxgoodsStock>) dao.findForList("mallDao.findWxgoodsStockList", id);
    }

    @Override
    public List<Ppics> findPicsById(String id) throws Exception {
        return (List<Ppics>) dao.findForList("mallDao.findPicsByMainid", id);
    }

    @Override
    public List<Map<String, Object>> findWxgoodsPropertyName(String id) throws Exception {
        return (List<Map<String, Object>>) dao.findForList("mallDao.findWxgoodsPropertyName", id);
    }

    @Override
    public void delGridById(String ids) throws Exception {
        String sql= StringUtil.formateString("update base_wxgoods set isdel=1 where id in({0})",StringUtil.formatSqlIn(ids));
        twxgoodsDao.executeSql(sql);
    }

    @Override
    public void updateStockAndPrice(Pwxgoods pwxgoods) throws Exception {
        String[] ids = pwxgoods.getStockId().split(",");
        String[] prices = pwxgoods.getPrice().split(",");
        String[] stocks = pwxgoods.getStock().split(",");

        if (ids != null && prices != null && stocks != null && ids.length == prices.length && ids.length == stocks.length) {
            Map<String, Object> params = new HashMap<>();
            for (int i = 0; i < ids.length; i++) {
                params.clear();
                params.put("id", ids[i]);
                params.put("price", prices[i]);
                params.put("stock", stocks[i]);
                dao.update("mallDao.updateStockAndPrice", params);

            }

        }
    }

    @Override
    public void addGoodAndStockFromChain(PwxGoods pwxGoodsSession, Pwxgoods pwxgoods,String mapId) throws Exception {
        //1 判断good是否存在,不存在add
        Map<String,Object> goodsMap = (Map<String, Object>) dao.findForObject("mallDao.getGoodsById", pwxGoodsSession.getId());
        if (goodsMap == null || StringUtil.isNullOrEmpty(goodsMap.get("id"))) {
            Twxgoods2 twxgoods = new Twxgoods2();
            twxgoods.setId(pwxGoodsSession.getId());
            twxgoods.setName(pwxGoodsSession.getName());
            twxgoods.setInfo(pwxGoodsSession.getComment());
            twxgoods.setIsSale((short)1);
            twxgoods.setVenderIdMain("");
            twxgoods.setBuyerId(mapId);
            twxgoods.setUnitId(pwxGoodsSession.getUnitId());
            twxgoods.setBrand(pwxGoodsSession.getBrand());
            twxgoods.setIsTicket(0);
            twxgoods.setGoodsIdSup(pwxGoodsSession.getId());
            twxgoods.setIsdel((short) 0);
            twxgoods.setCreateTime(pwxGoodsSession.getCreateTime());
            twxgoodsDao2.save(twxgoods);

            //图片
            List<PwxGoodsStock> coverList = pwxGoodsSession.getCoverList();
            if (coverList != null && coverList.size() > 0) {
                for (int i = 0; i < coverList.size(); i++) {
                    PwxGoodsStock pwxGoodsStock = coverList.get(i);
                    Tpics tpics = new Tpics();
                    tpics.setId(UuidUtil.get32UUID());
                    tpics.setMainId(pwxGoodsSession.getId());
                    tpics.setMainType(3);
                    tpics.setPath(pwxGoodsStock.getCoverPath());
                    picsDao.save(tpics);
                }
            }

        }

        //2 循环判断该good的stock是否存在,不存在add,存在跟新库存(价格?)
        List<PwxGoodsStock> stocklist = pwxGoodsSession.getStocklist();
        //String[] ids = pwxgoods.getStockId().split(",");
        //String[] prices = pwxgoods.getPrice().split(",");
        //String[] stocks = pwxgoods.getStock().split(",");
        Map<String, Object> stockParams = new HashMap<>();
        if (stocklist != null && stocklist.size() > 0) {
            for (int i = 0; i < stocklist.size(); i++) {
                PwxGoodsStock stock = stocklist.get(i);
                Map<String,Object> stockMap = (Map<String, Object>) dao.findForObject("mallDao.getGoodsStockById",stock.getId());
                stockParams.clear();
                if(stockMap !=null && !StringUtil.isNullOrEmpty(stockMap.get("id"))){
                    stockParams.put("id", stock.getId());
                    stockParams.put("addStock", stock.getStock());
                    //stock存在,更新库存
                    //dao.update("mallDao.updateStock", stockParams);
                }else{
                    //stock不存在,新增
                    TwxgoodsStock2 twxgoodsStock = new TwxgoodsStock2();
                    BeanUtils.copyProperties(stock,twxgoodsStock);
                    twxgoodsStock.setId(stock.getId());
                    twxgoodsStock.setPrice(stock.getPriceDiaopai());
                    twxgoodsStock.setStockNow(stock.getStock());
                    twxgoodsStock.setStockOccupy(0);
                    twxgoodsStock.setIsdel((short) 0);
                    wxgoodsStockDao2.save(twxgoodsStock);

                    //3 不存在的stock添加对应的property
                    TwxgoodsProperty twxgoodsProperty = null;
                    if(!StringUtil.isNullOrEmpty(stock.getTypesId1())){
                        twxgoodsProperty = new TwxgoodsProperty();
                        twxgoodsProperty.setId(stock.getTypesId1());
                        twxgoodsProperty.setGoodsId(stock.getGoodsId());
                        twxgoodsProperty.setType((short) 1);
                        twxgoodsProperty.setProperty(stock.getTypesId1());
                        twxgoodsProperty.setIsdel((short) 0);
                        twxgoodsProperty.setCreateTime(new Date());
                        wxgoodsPropertyDao.save(twxgoodsProperty);
                    }
                    if(!StringUtil.isNullOrEmpty(stock.getTypesId2())){
                        twxgoodsProperty = new TwxgoodsProperty();
                        twxgoodsProperty.setId(stock.getTypesId2());
                        twxgoodsProperty.setGoodsId(stock.getGoodsId());
                        twxgoodsProperty.setType((short) 1);
                        twxgoodsProperty.setProperty(stock.getTypesId2());
                        twxgoodsProperty.setIsdel((short) 0);
                        twxgoodsProperty.setCreateTime(new Date());
                        wxgoodsPropertyDao.save(twxgoodsProperty);
                    }
                    if(!StringUtil.isNullOrEmpty(stock.getTypesId3())){
                        twxgoodsProperty = new TwxgoodsProperty();
                        twxgoodsProperty.setId(stock.getTypesId3());
                        twxgoodsProperty.setGoodsId(stock.getGoodsId());
                        twxgoodsProperty.setType((short) 1);
                        twxgoodsProperty.setProperty(stock.getTypesId3());
                        twxgoodsProperty.setIsdel((short) 0);
                        twxgoodsProperty.setCreateTime(new Date());
                        wxgoodsPropertyDao.save(twxgoodsProperty);
                    }

                }

            }
        }

    }

    @Override
    public PwxGoods getGoodsAndStockById(String id) throws Exception {
        //加载商品详情
        PwxGoods good = (PwxGoods) dao.findForObject("mallDao.getGoodsDetail", id);
        //加载商品库存信息
        List<PwxGoodsStock> stockList = (List<PwxGoodsStock>)dao.findForList("mallDao.getGoodsStockById2", id);
        //加载商品库存信息
        List<PwxGoodsStock> stockParList = (List<PwxGoodsStock>)dao.findForList("mallDao.getGoodsStandarParNodeList", id);
        //加在商品论幅图
        PwxGoodsStock cover = new PwxGoodsStock();
        List<PwxGoodsStock> picPathList = new ArrayList<PwxGoodsStock>();
        if(!StringUtil.isNullOrEmpty(good.getId())){
            cover.setId(good.getId());
            picPathList = (List<PwxGoodsStock>)dao.findForList("mallDao.getGoodsCoverList",cover );
        }
        good.setCoverList(picPathList);
        good.setStocklist(stockList);
        good.setStockParList(stockParList);
        return good;
    }


    /**
     *
     * @param type 0新增 1跟新(未使用)
     * @param goodsVenderId
     * @param twxgoodsStock
     * @return
     * @throws Exception
     */
    public boolean isExsitedVenderId(int type,String goodsVenderId,TwxgoodsStock twxgoodsStock) throws Exception {
        boolean isExsited = false;
        Map<String, Object> params = new HashMap<>();
        params.put("goodsVenderId", goodsVenderId);
        params.put("stockVenderId", twxgoodsStock.getVenderId());
        List<Map<String, Object>> list = (List<Map<String, Object>>) dao.findForList("mallDao.isExsitedVenderId", params);

        if(type==0){
            if (list != null && list.size() > 0) {
                isExsited = true;
            }
        }else if(type==1){
        }

        return isExsited;

    }

    @Override
    public List<Map<String, Object>> findBrandSpeed() throws Exception {
        return (List<Map<String,Object>>) dao.findForList("mallDao.findBrandSpeed",null);
    }


    @Override
    public List<Pbrand> loadBrand() throws Exception {
        return (List<Pbrand>) dao.findForList("mallDao.loadBrand",null);
    }
}
